package com.timemanage.activity.ui.notifications

import android.os.Build
import android.os.Bundle

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment

import androidx.recyclerview.widget.LinearLayoutManager

import com.timemanage.R

import com.timemanage.dao.AppDatabase
import com.timemanage.dao.UserDao

import com.timemanage.entity.User
import com.timemanage.utils.MyApplication

import kotlinx.android.synthetic.main.fragment_notifications.*

class NotificationsFragment : Fragment() {

    var isCreated:Boolean = true
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_notifications,container,false)
        return view
    }
    @RequiresApi(Build.VERSION_CODES.O)
    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        var sortName = ArrayList<String>()
        var sortBody = ArrayList<String>()
        var sortId   = ArrayList<String>()
        var workstartTime = ArrayList<String>()
        var workendTime   = ArrayList<String>()

        var database= AppDatabase.getDatabase(MyApplication.context)
        var workDao = database.WorkDao()
        var sortDetailList = workDao.selectbaseType()
        for (i in sortDetailList) {
            val nowTime = System.currentTimeMillis()
            if(i.endTime!!>nowTime) {
                workstartTime.add(i.startTime.toString())
                workendTime.add(i.endTime.toString())
                sortName.add(i.title!!)
                sortBody.add(i.workbody!!)
                sortId.add(i.workId.toString())
            }
        }
        val todosAdapter = MyApplication.context?.let { this.activity?.let { it1 -> todoAdapter(it1, sortId,sortName, sortBody,workstartTime,workendTime) } }
        recycleViewTodo.adapter = todosAdapter
        recycleViewTodo.layoutManager = LinearLayoutManager(MyApplication.context)
    }

}